<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/inc/common.jsp"%>
<html>
<head>
<title>部门管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
	$(function() {
		initDg();//初始化datagrid
		setDgBut(0,0);//初始化datagrid按钮
	});
	//回车查询
	$(document).keydown(function(e){
		if(e.keyCode == 13) {
			searchDate();
		}
	});
	//初始化数据列表
	function initDg(){
		$('#dg').datagrid({
			url:'${basePath}/bus/notice/query.do',
			loadMsg:'数据装载中......',
		    title:'结果列表',//标题
		    width:'auto',//列表的宽度
			height:'auto',//列表的高度
			fit:true,//自动填充全屏
			nowrap: false,//数据是否显示在一行中
			fitColumns:true,//是否根据字体数收缩
		    pagination:true,//分页底部显示
		    pageList:[10,20,30],//设置分页下拉页数
		    rownumbers : true,//显示行号
			//singleSelect:true,//只能单选
			autoRowHeight:false,//自动行高
			idField : 'id',
		    columns:[[
				{field:'ck',checkbox:'true'},
				{field:'titel',title:'标题',width:fixWidth(20),align:'center'},//宽度百分10
				{field:'userName',title:'创建人',width:fixWidth(20),align:'left'},
				{field:'createTime',title:'创建时间',width:fixWidth(20),align:'left',
					formatter:function(value,row,index){
						return changeDateToString(value);
					}
				}
			]],
		    toolbar:[
		        {
		        	id : 'dg-add',
					text : '新增',
					iconCls : 'icon-add',
					handler : function() {
						editData();
					}
				},'-',{
					id : 'dg-edit',
					text : '修改',
					iconCls : 'icon-edit',
					handler : function() {
						var row = $('#dg').datagrid('getSelected');
						if (row) {
							editData(row.id);
						}else{
								$.messager.alert('消息', "请选择一条信息!",'info');	
							}
					}
				},'-',{
					id : 'dg-delete',
					text : '删除',
					iconCls : 'icon-delete',
					handler : function() {
						var row = $('#dg').datagrid('getSelections');
						if (row && row.length>0){
							$.messager.confirm('系统提示', '您确定要删除该条数据吗?', function(r) {
								if(r){
									deleteData(row);
								}
							});
						}else{
								$.messager.alert('消息', "请选择一条信息!",'info');	
						}
					}
				}
		   	],
            onSelect: function (index, row) {
            	setDgBut(1,1);//设置单选的按钮状态
            },
            onUnselect: function (index, row) {
            	setDgBut(2,1);//设置取消单选的按钮状态
            },
            onSelectAll: function (index, row) {
            	setDgBut(3,index.length);//设置全选的按钮状态
            },
            onUnselectAll: function (index, row) {
            	setDgBut(2,index.length);//设置取消全选的按钮状态
            }
		});
	}
	
	//查询
	function searchDate(){
		var params = $('#dg').datagrid('options').queryParams; //先取得 datagrid 的查询参数
        var fields =$('#searchForm').serializeArray(); //自动序列化表单元素为JSON对象  
        $.each( fields, function(i, field){
            params[field.name] = field.value; //设置查询参数  
        });
        $('#dg').datagrid('reload'); //设置好查询参数 reload 一下就可以了 
	}
	
	//编辑
	function editData(id){
		if(id != null && id != "undefined" && id != ""){
			window.location.href="${basePath}/bus/notice/edit.do?id="+id;
		}else{
			window.location.href="${basePath}/bus/notice/edit.do";
		}
	}
	
	//删除
	function deleteData(row){
		var ids = "";
		for(var i=0;i<row.length;i++){
			ids = ids+","+row[i].id;
		}
		if(ids!="" && ids.length>0){
			ids = ids.substring(1, ids.length);
			$.ajax({
	            url:'${basePath}/bus/notice/delete.do',  
	            type:'post',         
	            data:"ids="+ids, 
	            dataType:"json",
	            success:function(msg){
	            	$.each(msg,function(i,n){
	            		if(n.message == "success"){
	            			$('#dg').datagrid('reload');
	            		}else{
	            			$.messager.alert('消息', "失败!请重新操作!");
	            		}
	               });
	                 
	           	}
	         });
		}
	}
	//清空
	function cleanDate(){
		$('#searchForm').form('clear');
	}
	
</script>
</head>
<body>
		<div class="easyui-layout" fit="true">
			<div data-options="region:'north', title:'查询条件',split:true,collapsed:false,footer:'#searchfooter'" style="overflow: hidden;">
			<!-- 查询条件 -->
			<div style="padding:10px 5px 45px 20px;">
			<form id="searchForm" name="searchForm" style="margin-bottom: 0px;">
					<table class="search-table"  width="100%" cellpadding="0" cellspacing="0" border="0">
						<tr>
							<td align="right" width="10%">标题:</td>
							<td width="15%">
								<input class="easyui-textbox" type="text" id="titel" name="titel"></input>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<!-- 搜索按钮 -->
			<div id="searchfooter" style="text-align:right;padding: 0px 10px">
				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="searchDate()"  data-options="iconCls:'icon-search',plain:true" >查询</a>
				<span class="search-btn-separator"></span>
				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="cleanDate()" data-options="iconCls:'icon-cross',plain:true">重置</a>
			</div>
		</div>
		<!-- 数据列表 -->
		<div region="center" split="true" border="false" style="overflow: hidden;width: 99%;height: auto">
			<table id="dg"></table>
		</div>
	</div>
</body>
</html>
